<?php
  $yhendus=new mysqli("localhost", "if13", "ifikad", "if13_sillasmi_e");
  if(isSet($_REQUEST["ansambel_id"])){
     $kask=$yhendus->prepare("UPDATE ansamblid SET punktid=punktid+1 WHERE id=?");
	 $kask->bind_param("i", $_REQUEST["ansambel_id"]);
	 $kask->execute();
  }
  if(isSet($_REQUEST["ansambel_id2"])){
     $kask=$yhendus->prepare("UPDATE ansamblid SET punktid=punktid-1 WHERE id=?");
	 $kask->bind_param("i", $_REQUEST["ansambel_id2"]);
	 $kask->execute();
  }
?>
<!doctype html>
<html>
  <head>
    <title>Ansamblid</title>
  </head>
  <body>
    <h1>Ansamblid</h1>
    <table>
	  <?php
	     $kask=$yhendus->prepare("SELECT id, ansamblinimi, punktid FROM ansamblid");
		 $kask->bind_result($id, $ansamblinimi, $punktid);
		 $kask->execute();
		 while($kask->fetch()){
		    $ansamblinimi=htmlspecialchars($ansamblinimi);
		    echo "<tr>
			  <td>$ansamblinimi</td>
			  <td>$punktid</td>
			  <td><a href='?ansambel_id=$id'>Lisa punkt</a></td>
			  <td><a href='?ansambel_id2=$id'>Eemalda punkt</a></td>
			</tr>";
		 }
	  ?>
	</table>
  </body>
</html>
<?php
  $yhendus->close();
?>